#ifndef SOCKET_H
#define SOCKET_H

#include "NetworkByteArray.h"
#include "Exception.h"
#include <netinet/in.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>

#include <sstream>

class Socket
{
protected:
	Socket( int socketId, int protocol );
public:
	Socket( const Socket &socket );
    Socket( int protocol )  throw ( Exception );

    ~Socket( void );

	Socket * acceptConnection( void ) throw ( Exception );
	
	bool connectTo( std::string host, int port )  throw ( Exception );
	void bindSocket( int port )  throw ( Exception );
	void listenSocket( int maxConnections )  throw ( Exception );
	
	void closeSocket( void )  throw ( Exception );
	
	void writeData( NetworkByteArray * data ) throw ( Exception );
	NetworkByteArray * readData( void ) throw ( Exception );
	
	static const int SOCKET_TCP;
	static const int SOCKET_UDP;
	static const int SOCKET_INVALID_ERROR;
	static const int SOCKET_ERROR;
private:

	static const int SOCKET_DATA_BUFFER_MAX_SIZE;
	
	int m_socketId;
	int m_protocol;
	bool m_isConnected;
	

};

#endif
